package com.usian.article.controller;

import com.usian.article.ApArticleControllerApi;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.dto.ArticleDto;
import com.usian.model.article.dto.ArticleHomeDto;
import com.usian.model.article.dto.ArticleInfoDto;
import com.usian.model.article.pojos.ApArticle;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * admin 远程调用保存文章主表
     *
     * @param apArticle
     * @return
     */
    @Override
    @RequestMapping("/saveApArticle")
    public ApArticle saveApArticle(@RequestBody ApArticle apArticle) {
        return apArticleService.saveApArticle(apArticle);
    }
    /**
     * app 文章查询列表 默认
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadList((short)1,dto);
    }

    /**
     * app 文章查询列表 上拉加载更多
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadList((short)1,dto);
    }

    /**
     * app 文章查询列表 下拉加载最新
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadList((short)2,dto);
    }

    /**
     * app 文章查询详情
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load_article_info")
    public ResponseResult loadDetail(@RequestBody ArticleDto dto) {
        return apArticleService.loadDetail(dto);
    }
    @Override
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto) {
        return apArticleService.loadArticleBehavior(dto);
    }

    @Override
    @PostMapping("/findArticleList")
    public List<ApArticle> findArticleList() {
        return apArticleService.list();
    }
}
